﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.Framework.Configurations.Core
{
    class XmlConstraintPropertyFactory<T> : IXmlConstraintPropertyFactory<T>
    {
        string elementName = null;

        string propertyName = null;

        List<IXmlConstraintProperty> list = null;

        public XmlConstraintPropertyFactory(string elementName, string propertyName,
            List<IXmlConstraintProperty> list)
        {
            this.elementName = elementName;
            this.propertyName = propertyName;
            this.list = list;
        }

        public void Great(T value)
        {
            Great(value, null);
        }

        public void GreatEqual(T value)
        {
            GreatEqual(value, null);
        }

        public void Less(T value)
        {
            Less(value, null);
        }

        public void LessEqual(T value)
        {
            LessEqual(value, null);
        }

        public void Equal(T value)
        {
            Equal(value, null);
        }

        public void NotEqual(T value)
        {
            NotEqual(value, null);
        }

        public void Great(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlGreatConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public void GreatEqual(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlGreatEqualConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public void Less(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlLessConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public void LessEqual(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlLessEqualConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public void Equal(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlEqualConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public void NotEqual(T value, string format)
        {
            if (value == null)
                throw new Exception("missing input value.");

            list.Add(new XmlNotEqualConstraintProperty<T>(elementName, propertyName, value, format));
        }

        public override string ToString()
        {
            return elementName + "." + propertyName;
        }
    }
}
